"""
接口：hs_const
描述：获取沪股通、深股通成分数据
"""

from app_config import get_engine, get_pro
from _stock_basic import read_data

engine = get_engine()


def get_data(hs_type):
    pro = get_pro()
    # 获取沪股通成分
    stock_base = read_data()
    df = pro.hs_const(hs_type=hs_type)
    merge = df.merge(stock_base, on='ts_code', how='left')
    # merge.drop(columns=['out_date', 'is_new'], axis=1, inplace=True)
    merge.to_excel('./1_1_5_hs_const'+hs_type+'.xlsx', index=False)
    print(merge)


if __name__ == '__main__':
    # 获取沪股通成分
    get_data("SH")
    # 获取深股通成分
    get_data("SZ")
